/*
    Clock.cpp

    Date:
        05-09-10

    Descripton:
        A simple clock with a single hour hand

    Authors:
        Nathaniel Brown
        Subodh Prabhu
        Jesus Suarez
*/


/****************************************************************************/
/*                              I N C L U D E S                             */
/****************************************************************************/

#include "GlutHeaders.h"
#include "Clock.h"
#include "DrawGraphics.h"
#include "Theme.h"

/****************************************************************************/
/*                               E X T E R N S                              */
/****************************************************************************/

extern Theme thm;

/****************************************************************************/
/*              C L O C K   :   M E M B E R   F U N C T I O N S             */
/****************************************************************************/

Clock::Clock() {
  time_t rawtime;
  struct tm * time_info;
  time(&rawtime);
  time_info = localtime(&rawtime);

  curr_time = (double) (time_info->tm_hour % 12)
            + (double) time_info->tm_min / 60
            + (double) time_info->tm_sec / 3600;
  prev_time = time(NULL);
}

void
Clock::drawFace() {
  glColor4f(thm.faceColor.r, thm.faceColor.g, thm.faceColor.b, thm.faceColor.t);
  drawDisk();
  
  glColor4f(thm.ringColor.r, thm.ringColor.g, thm.ringColor.b, thm.ringColor.t);
  drawCircle();
  for (double d = 0; d < 12; ++d)
    drawTick(d);
}

void
Clock::drawHand() {
  glColor3f(0.0, 0.0, 0.0);
  drawLine(curr_time);
  curr_time += difftime(time(NULL), prev_time) / 3600;
  while(curr_time > 12) curr_time -= 12;
  prev_time = time(NULL);
}

void
Clock::setTime(int hour, int minute) {
  if(hour > 0 && hour < 24
    && minute >= 0 && minute < 60) {
      curr_time = (double) (hour % 12)
                + (double) minute / 60;
  }
}

double
Clock::getTime() {
  return curr_time;
}
